package com.jackeysun.widget

import android.text.method.LinkMovementMethod
import android.widget.TextView
import android.text.Spannable
import android.view.MotionEvent
import android.text.method.MovementMethod
import android.text.NoCopySpan.Concrete

/**
 * Created by sunxunchao on 2021/9/30.
 */
class OverLinkMovementMethod : LinkMovementMethod() {
    override fun onTouchEvent(widget: TextView, buffer: Spannable, event: MotionEvent): Boolean {
        val action = event.action
        if (action == MotionEvent.ACTION_MOVE) {
            if (!canScroll) {
                return true
            }
        }
        return super.onTouchEvent(widget, buffer, event)
    }

    companion object {
        var canScroll = false
        val instance: MovementMethod?
            get() {
                if (sInstance == null) sInstance = OverLinkMovementMethod()
                return sInstance
            }
        private var sInstance: OverLinkMovementMethod? = null
        private val FROM_BELOW: Any = Concrete()
    }
}